<!doctype html>
<html class="en">
<head>
    <!-- 公共css、js -->
    {include file="public/static" /}
    <!-- 公共css、js end -->
    <link rel="stylesheet" href="__static__/css/login.css">
</head>
<body>
    <div class="show">
        <div class="show-body">
            <!-- 欢迎标语 -->
            <div class="welcome">
                <div class="welcome-top">WELCOME LOGIN！</div>
                <div class="welcome-text">欢迎登录后台管理！</div>
            </div>
            <!-- 登录框 -->
            <div class="show-frame">
                <div class="show-form">
                    <div class="show-form-top">
                        <p class="title"><span>LOGIN</span> 用户登录</p>
                    </div>
                    <div class="show-form-min">
                        <form class="frame-form layui-form">
                            <div class="form-item">
                                <div class="form-block">
                                    <div class="form-label"><img class="img-user" src="__static__/images/user.png"></div>
                                    <input type="text" class="form-input" name="username" placeholder="输入用户名" lay-verify="username"/>
                                </div>
                            </div>
                            <div class="form-item">
                                <div class="form-block">
                                    <div class="form-label"><img class="img-pwd" src="__static__/images/password.png"></div>
                                    <input type="password" class="form-input" name="password" placeholder="输入密码" lay-verify="password"/>
                                </div>
                            </div>
                            <div class="form-item">
                                <div class="form-block code">
                                    <div class="form-label"><img class="img-pwd" src="__static__/images/code.png"></div>
                                    <input type="text" maxlength="5" class="form-input code-input" name="code" placeholder="输入验证码" lay-verify="code"/>
                                </div>
                                <img id="code" class="form-code" src="{:url('Login/verify')}" onclick="changeCode()" title="点击切换验证码" />
                            </div>
                            <button type="button" class="input-bottom" lay-submit lay-filter="login">登 录</button>
                        </form>
                    </div>
                </div>
                <div class="show-support">
                    <p>技术支持：{$support.email}</p>
                </div>
            </div>
            <!-- 底部颜色 -->
            <div class="show-bottom">
                <div class="show-bottom-title">{$webInfo.sy_website}</div>
                <div class="show-bottom-text">欢迎登录后台管理！</div>
            </div>
        </div>
    </div>

    <script>
        $(function () {
            var button = document.querySelector(".input-bottom");
            //监听回车键
            document.onkeydown = function(e){
                //火狐中是 window.event
                if(!e) e = window.event;
                if((e.keyCode || e.which) == 13){
                    button.click();
                    //取消监听
                    button.setAttribute("lay-filter", "");
                    //计时器
                    setTimeout(function () {
                        button.setAttribute("lay-filter", "login"); //恢复监听
                    }, 1500)
                }
            };
            layui.use('form', function(){
                var form = layui.form;
                //验证
                form.verify({
                    username: function (value) {
                        if(value == ""){
                            return "用户名不能为空";
                        }
                    },
                    password: function (value) {
                        if(value == ""){
                            return "密码不能为空";
                        }
                    },
                    code: function (value) {
                        if(value == ""){
                            return "验证码不能为空";
                        }
                    }
                });
                //监听提交
                form.on('submit(login)', function(data){
                    $.ajax({
                        type:"POST",
                        url: "{:url('Login/loginCheck')}",
                        data: data.field,
                        success:function (data) {
                            if(data.status === 1){
                                layer.msg(data.info,{icon:6,time:1500},function () {
                                    //是否在iframe中打开
                                    if (window.frames.length != parent.frames.length) {
                                        parent.location.reload();
                                    }else{
                                        window.location.href = data.url
                                    }
                                });
                            }else{
                                layer.msg(data.info,{icon:5,time:1500},function () {
                                    changeCode();
                                });
                            }
                        }
                    });
                });
            });
        });
        /*切换验证码*/
        function changeCode(){
            var ts = Date.parse(new Date())/1000;
            $('#code').attr("src", "{:url('Login/verify')}?id="+ts);
        }
    </script>
    <!-- 底部结束 -->
</body>
</html>